strftime(buff, sizeof(buff), "%d-%b-%y %H:%M:%S", &tm);
strupper(buff);
}
+ else strncpy(buff, "01-JAN-70 00:00:00", sizeof(buff));
gbfprintf(fout, "T A %.10f%c%c %.10f%c%c ",
fabs(wpt->latitude), 0xBA, (wpt->latitude >= 0) ? 'N' : 'S',
} ppdb_appdata_t;
#define PPDB_APPINFO_SIZE sizeof(struct ppdb_appdata)
+static ppdb_appdata_t *appinfo;
static char *opt_dbname = NULL;
static char *opt_deficon = NULL;
file_out = pdb_create(fname, MYNAME);
mkshort_handle = mkshort_new_handle();
ct = 0;
+ appinfo = NULL;
if (global_opts.synthesize_shortnames != 0)
{
str_pool_deinit();
xfree(fname_out);
if (datefmt) xfree(datefmt);
+ if (appinfo) xfree(appinfo);
}
/*
static void ppdb_write(void)
{
- ppdb_appdata_t *appinfo = NULL;
if (opt_dbname)
strncpy(file_out->name, opt_dbname, PDB_DBNAMELEN);
- file_out->name[PDB_DBNAMELEN-1] = 0;
file_out->attr = PDB_FLAG_BACKUP;
file_out->ctime = file_out->mtime = current_time() + 2082844800U;
file_out->creator = PPDB_MAGIC;
if (global_opts.objective != wptdata) /* Waypoint target do not need appinfo block */
{
- appinfo = xcalloc(PPDB_APPINFO_SIZE, 1);
-
+ appinfo = xcalloc(1, sizeof(*appinfo));
file_out->appinfo = (void *)appinfo;
file_out->appinfo_len = PPDB_APPINFO_SIZE;
}
fatal(MYNAME ": Realtime positioning not supported.\n");
break;
}
-
- if (appinfo != NULL) xfree(appinfo);
}
pdbrec_t *rec;
/* load the header */
- fin->name = xcalloc(1, 32 + 1);
- gbfread(fin->name, 1, 32, fin->file);
-
+ gbfread(fin->name, 1, PDB_DBNAMELEN, fin->file);
+ fin->name[PDB_DBNAMELEN] = '\0';
+
fin->attr = gbfgetuint16(fin->file);
fin->version = gbfgetuint16(fin->file);
fin->ctime = gbfgetuint32(fin->file);
pdbfile *res;
res = xcalloc(1, sizeof(*res));
- res->name = xmalloc(PDB_DBNAMELEN + 1);
strncpy(res->name, "Palm/OS Database", PDB_DBNAMELEN);
res->file = gbfopen_be(filename, "wb", module);;
res->mode = 2;
}
len = strlen(file->name);
- if (len > 32) len = 32;
gbfwrite(file->name, 1, len, fout);
- while (len++ < 32) gbfputc(0, fout);
+ while (len++ < PDB_DBNAMELEN) gbfputc(0, fout);
gbfputuint16(file->attr, fout);
gbfputuint16(file->version, fout);
gbfwrite(file->appinfo, 1, file->appinfo_len, fout);
}
- rec = file->rec_list;
- while (rec) {
- gbfwrite(rec->data, 1, rec->size, fout);
- rec = rec->next;
+ for (rec = file->rec_list; rec; rec = rec->next) {
+ if (rec->size > 0)
+ gbfwrite(rec->data, 1, rec->size, fout);
}
}
gbfclose(file->file);
if ((file->mode & 1) && file->appinfo) xfree(file->appinfo);
- xfree(file->name);
rec = file->rec_list;
while (rec) {
typedef struct {
gbfile *file;
char mode; /* file-mode: 1 = read / 2 = write */
- char *name; /* database name */
+ char name[PDB_DBNAMELEN + 1]; /* database name */
gbuint16 attr; /* attributes */
gbuint16 version; /* version */
time_t ctime; /* creation time */